enum PositionGroup
{
    t0,
    t1,
    t2,
    t3,
    t4,
    t5,
    t6,
    t7,
    t8,
    t9,
    d0,
    d1,
    d2,
    d3,
    d4,
    d5,
    d6,
    d7,
    d8,
    d9,
    

}
interface PresetPointData
{
    point:lg.Point;
    used:boolean;
    positionGroup:PositionGroup;
}
 class Cat extends lg.Container
{
    public _skin:lg.Sprite;
    constructor()
    {
        super();
        
        this.addEventListener("added", this.addedHandler);
    }
    private addedHandler(e) {
        e.target.removeEventListener("added", e.target.addedHandler);
        e.target.initView();
    }
    private initView()
    {
        var flameSheet: lg.SpriteSheet = new lg.SpriteSheet({ images: ["../res/assets/images/cat.png"], frames: [[0,0,720,887,0,360,887],[0,887,720,887,0,360,887]]});
        this._skin = new lg.Sprite(flameSheet);
        this._skin.stop();
        // this._skin.play();
        // this.initData();
        this.addChild(this._skin);
    }
    public initData()
    {
        this._presetPoints=new Array<PresetPointData>();

        var ppds=window["presetPoints"];
        for(var i=0;i<ppds.length;i++)
        {
            var ppd=ppds[i];
             this._presetPoints.push({point:new lg.Point(ppd.x,ppd.y),used:ppd.used,positionGroup:<PositionGroup>ppd.id});
        }
       
        // this._presetPoints.push({point:new lg.Point(-72,-658),used:false,positionGroup:PositionGroup.t1});
        // this._presetPoints.push({point:new lg.Point(-33,-652),used:false,positionGroup:PositionGroup.t2});
        // this._presetPoints.push({point:new lg.Point(-6,-648),used:false,positionGroup:PositionGroup.t3});
        // this._presetPoints.push({point:new lg.Point(22,-644),used:false,positionGroup:PositionGroup.t4});
        // this._presetPoints.push({point:new lg.Point(62,-644),used:false,positionGroup:PositionGroup.t5});
        // this._presetPoints.push({point:new lg.Point(92,-650),used:false,positionGroup:PositionGroup.t6});
        // this._presetPoints.push({point:new lg.Point(121,-658),used:false,positionGroup:PositionGroup.t7});
        // this._presetPoints.push({point:new lg.Point(166,-658),used:false,positionGroup:PositionGroup.t8});
        // this._presetPoints.push({point:new lg.Point(196,-654),used:false,positionGroup:PositionGroup.t9});
        // this._presetPoints.push({point:new lg.Point(-109,-533),used:false,positionGroup:PositionGroup.d0});
        // this._presetPoints.push({point:new lg.Point(-71,-522),used:false,positionGroup:PositionGroup.d1});
        // this._presetPoints.push({point:new lg.Point(-35,-516),used:false,positionGroup:PositionGroup.d2});
        // this._presetPoints.push({point:new lg.Point(-7,-518),used:false,positionGroup:PositionGroup.d3});
        // this._presetPoints.push({point:new lg.Point(26,-520),used:false,positionGroup:PositionGroup.d4});
        // this._presetPoints.push({point:new lg.Point(57,-520),used:false,positionGroup:PositionGroup.d5});
        // this._presetPoints.push({point:new lg.Point(92,-527),used:false,positionGroup:PositionGroup.d6});
        // this._presetPoints.push({point:new lg.Point(126,-514),used:false,positionGroup:PositionGroup.d7});
        // this._presetPoints.push({point:new lg.Point(159,-521),used:false,positionGroup:PositionGroup.d8});
        // this._presetPoints.push({point:new lg.Point(196,-533),used:false,positionGroup:PositionGroup.d9});
        this._skin.framerate=0;
        // this._skin.gotoAndStop(0);
        this._skin.gotoAndStop(1);
    }
    
    public getEnemyPoint():lg.Point
    {
        var p:lg.Point=new lg.Point();
        var intervalW=215-(-125);
        var intervalH=675-628;
        var rw=Math.random()*intervalW;
        var rh=Math.random()*intervalH;
        p.x=-125+rw;
        p.y=-675+rh;
        // -125,-675
        // 215,-675
        //  -125,-628,
        //  215,-628
        return this.localToGlobal(p.x,p.y);
    }

    private _presetPoints:Array<PresetPointData>;
    public getEnemyPresetPointDataByPreset():PresetPointData
    {
        
        var index=Math.floor(Math.random()*this._presetPoints.length);
        var ppd:PresetPointData=this._presetPoints[index];
        if(ppd.used)
        {
            ppd=this.getEnemyPresetPointDataByPreset();
        } else
        {
            this._presetPoints[index].used=true;
        }
        return ppd;
    }
    public getEnemyPresetPointDataByPositionGroup(v:PositionGroup)
    {
         var ppd:PresetPointData=this._presetPoints[v];
        if(ppd.used)
        {
            ppd=this.getEnemyPresetPointDataByPreset();
        } else
        {
            this._presetPoints[v].used=true;
        }
        return ppd;
    }
    private getEnemyPointByPreset():lg.Point
    {
        var p:lg.Point=new lg.Point();
        var ppd:PresetPointData=this.getEnemyPresetPointDataByPreset();
        p=this.localToGlobal(ppd.point.x,ppd.point.y);
        // console.log(ppd.point.x,ppd.point.y,p.x,p.y,ppd)
        return p;
    }
}